package net.sourceforge.krama.introspection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

public class TIntrospection {

	public static Object getResult(TMethod tMethod, Object[] paramValue){
		Object result = null;
		try {
			Class<?> className = Class.forName(tMethod.getClasse());
			Object classInstance = className.newInstance();
			List<String> paramsList = tMethod.getParams();
			Class[] parameterTypes = new Class[paramsList.size()] ;
			Object[] arg = new Object[paramsList.size()];
			for(int i = 0; i < paramsList.size(); i++ ){
				Class<?> typeParam = Class.forName(paramsList.get(i));
				parameterTypes[i] = typeParam;
			}
			
			Method methodeName = classInstance.getClass().getDeclaredMethod(tMethod.getMethode(), parameterTypes);
			result = methodeName.invoke(classInstance, (Object[]) paramValue);
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return result;
	}
	
	public static Object getView(String view){
		Object result = null;
		try {
			Class<?> className = Class.forName(view);
			result = className.newInstance();
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
}
